import {nextTick} from "../utils/next-tick";

let queue = []
let has = {}
let waiting = false
function flushSchedulerQueue(){
    console.log('更新开始')
    queue.forEach(watcher=>watcher.get())
    queue = []
    has = {}
    waiting = false
}
export function queueWatcher(watcher) {
  const id = watcher.id
  if (has[id] == null) {
    has[id] = true
    queue.push(watcher)
    if (!waiting) {
      waiting = true
      nextTick(flushSchedulerQueue)
    }
  }
}
